#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

typedef long long ll;
typedef vector < int > vec;
typedef pair < int , int > pii;

ll read() {
    ll x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int L = 1e7 + 10;
const int N = 1e5 + 10;

int n, m, val[L], ndn, ch[L][2], op[N], fa[L];
ll x[N], y[N];
bool ans[N];
vector < pii > G[N];
ll tot;

inline int newd(int v) { return val[++ndn] = v, ndn; }
inline void pd(int x) { ch[x][0] = ch[x][0] ? ch[x][0] : newd(val[x]); ch[x][1] = ch[x][1] ? ch[x][1] : newd(val[x]); val[x] = 0; }

void insert(int o, ll xl, ll xr, int v, ll l = 0, ll r = tot) {
	if(xl == l && xr == r) return val[o] = v, void(); pd(o); ll mid = l + r >> 1;
	if(xr <= mid) insert(ch[o][0], xl, xr, v, l, mid); else if(xl > mid) insert(ch[o][1], xl, xr, v, mid + 1, r);
	else insert(ch[o][0], xl, mid, v, l, mid), insert(ch[o][1], mid + 1, xr, v, mid + 1, r); 
}

void solve(int x, int y) {
	if(val[x] && val[y]) return G[min(val[x], val[y])].pb({ x, y }), void();
	if(val[x]) return solve(x, ch[y][0]), solve(x, ch[y][1]), void();
	if(val[y]) return solve(ch[x][0], y), solve(ch[x][1], y), void();
	return solve(ch[x][0], ch[y][0]), solve(ch[x][1], ch[y][1]);
}

int query(int o, ll pos, ll l = 0, ll r = tot) {
	if(val[o]) return o; ll mid = l + r >> 1;
	if(pos <= mid) return query(ch[o][0], pos, l, mid); else return query(ch[o][1], pos, mid + 1, r);
}

inline int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); }
inline void merge(int x, int y) { x = gf(x); y = gf(y); fa[x] = y; }

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in, m = in; tot = 1ll << n; tot--;
	rep(i, 1, m) {
		static char s[7]; scanf("%s", s);
		if(s[0] == 'a') op[i] = 1; else op[i] = 0;
		x[i] = in, y[i] = in;
	}
	newd(m + 1);
	rep(i, 1, m)
		if(op[i] == 0) insert(1, x[i], y[i], i);
	rep(x, 1, ndn) if(ch[x][0] && ch[x][1]) solve(ch[x][0], ch[x][1]);
	rep(i, 1, ndn) fa[i] = i;
	per(i, m, 1) {
		for(auto d : G[i + 1]) merge(d.fi, d.se);
		if(op[i]) {
			//cerr << query(1, x[i]) << " " << val[query(1, x[i])] << " " << query(1, y[i]) << " " << val[query(1, y[i])] << endl; 
			ans[i] = gf(query(1, x[i])) == gf(query(1, y[i]));
		}
	}
	rep(i, 1, m) if(op[i]) printf("%d\n", ans[i]);
	return 0;
}
